<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>毕业论文管理系统</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
<link rel="shortcut icon"
	href="${pageContext.request.contextPath }/favicon.ico"
	type="${pageContext.request.contextPath }/image/x-icon" />
<link rel="stylesheet"
	href="${pageContext.request.contextPath }/css/font.css">
<link rel="stylesheet"
	href="${pageContext.request.contextPath }/css/xadmin.css">
<script type="text/javascript"
	src="${pageContext.request.contextPath }/js/jquery-3.3.1.min.js"></script>
<script src="${pageContext.request.contextPath }/lib/layui/layui.js"
	charset="utf-8"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath }/js/xadmin.js"></script>
<!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
<!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
	<div class="x-body">
		<fieldset class="layui-elem-field">
			<legend>发布我的选题</legend>
			<br /> <br />
			<form class="layui-form" action="">
				<div class="layui-form-item">
					<label class="layui-form-label">上传论文</label>
					<div class="layui-input-block">
						<button type="button" class="layui-btn" id="test1">
							<i class="layui-icon">&#xe67c;</i>上传论文
						</button>
					</div>
				</div>
				<input name="student_no" type="hidden" value="${student.no }" />
				<div class="layui-form-item">
					<label class="layui-form-label">论文阶段</label>
					<div class="layui-input-block" style="width: 250px;">
						<select name="stage" id="stage" lay-verify="required">
							<option value=""></option>
							<option value="初稿">初稿</option>
							<option value="一稿">一稿</option>
							<option value="二稿">二稿</option>
							<option value="三稿">三稿</option>
							<option value="终稿">终稿</option>
						</select>
					</div>
				</div>
				<div class="layui-form-item layui-form-text">
					<label class="layui-form-label">修改概要</label>
					<div class="layui-input-block">
						<textarea name="modify" id="modify" style="width: 80%;" placeholder="请输入你论文的修改内容概要"
							class="layui-textarea"></textarea>
					</div>
				</div>
				<div class="layui-form-item">
					<div class="layui-input-block">
						<input value="提交" lay-submit lay-filter="publish" class="layui-btn" type="submit">
					</div>
				</div>
			</form>

			<script>
				var file_name;
				var file_path;
				layui.use('upload', function() {
					var upload = layui.upload;
					//执行实例
					var uploadInst = upload.render({
						elem : '#test1', //绑定元素
						url : '${pageContext.request.contextPath }/uploadFile.do', //上传接口
						/* data : {no : $("#student_no").val()}, */
						accept : 'file',
						done : function(data) {
							//上传完毕回调
							if (data.code == 0) {
								layer.msg(data.msg);
								file_path = data.filePath;
								file_name = data.fileName;
							}
						},
						error : function() {
							//请求异常回调
						}
					});
				});
				  layui.use('form', function(){
			          var form = layui.form;
			          form.on('submit(publish)', function(data){
						if(file_path != null && file_path != "" && file_name != null && file_name != ""){
				        	var stage = $(" #stage ").val();
				        	var modify = $(" #modify ").val();
				        	var student_no = $(" input[ name='student_no' ] ").val();
							$.ajax({
					        	url : "${pageContext.request.contextPath }/student/publishThesis.do",
					        	type : "post", 
					        	data : JSON.stringify({
						        		file_name : file_name,
						        		file_path : file_path,
						        		stage : stage,
						        		modify : modify,
						        		student_no : student_no
					        		}),
					        	contentType : "application/json;charset=UTF-8",
					        	dataType : "json",
					        		//成功响应的结果
					        	success : function(data){
					        		if(data != null){					
					        			layer.msg(data.msg,{time:2000});
					        		}
					        	}
					        }); 
					 	}else{
						 	layer.msg("你尚未上传论文，不能提交，请先上传论文再提交！");
						}
			          	return false;
			    	});
			    });
			</script>
		</fieldset>
	</div>
</body>
</html>